package com.xiaoshuidi.cloud.module.iot.enums;

import org.springframework.util.StringUtils;

/**
 * 水滴平台的通用开门类型
 * 会员类型(开门类型 0暂时未做 1密码开门  2动态密码开门 3APP蓝牙开门 4指纹开门 5门卡开门 6离线密码 )
 * 同时用于映射到前后端交互的授权（密码）类型，null,代表前后端映射时后端不提供或者不需要映射的授权类型，比如动态密码，后端有专门提供给前端接口进行动态密码获取，且动态密码获取记录不入库
 */
public enum CommonOpenDoorType {
    PASS_OPEN("1", "tenantPwd", "密码开门", PasswordTypeEnum.PASSWORD),
    DYNAMIC_OPEN("2", "dynamicPwd", "动态密码", null),
    APP_BLT_OPEN("3", "bluetoothPwd", "APP蓝牙开门", PasswordTypeEnum.APP_BLUE_TOOTH),
    FINGER_PRINT_OPEN("4", "fingerprintPwd", "指纹开门", PasswordTypeEnum.FINGER_DIGIT),
    CARD_OPEN("5", "cardPwd", "门卡开门", PasswordTypeEnum.GATE_CARD),
    OFFLINE_OPEN("6", "offlinePwd", "离线密码", PasswordTypeEnum.OFFLINE_PASSWORD),
    // 第三方设备有的开门方式,但系统未对接的功能
    NO_APPLY("0", "noApply", "密码失效", null);
    private String code;
    private String desc;
    private String chineseDesc;
    private PasswordTypeEnum passwordTypeEnum;

    CommonOpenDoorType(String code, String desc, String chineseDesc, PasswordTypeEnum passwordTypeEnum) {
        this.code = code;
        this.desc = desc;
        this.chineseDesc = chineseDesc;
        this.passwordTypeEnum = passwordTypeEnum;
    }

    public String getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public void setChineseDesc(String chineseDesc) {
        this.chineseDesc = chineseDesc;
    }

    public PasswordTypeEnum getPasswordTypeEnum() {
        return passwordTypeEnum;
    }

    public void setPasswordTypeEnum(PasswordTypeEnum passwordTypeEnum) {
        this.passwordTypeEnum = passwordTypeEnum;
    }

    public String getChineseDesc() {
        return chineseDesc;
    }

    public static CommonOpenDoorType getInstanceByOpenDoorTypeCode(String openDoorTypeCode) {
        if (StringUtils.isEmpty(openDoorTypeCode)) {
            return null;
        }
        for (CommonOpenDoorType instance : values()) {
            if (instance.getCode().equals(openDoorTypeCode)) {
                return instance;
            }
        }
        return null;
    }
}

